//package com.krtech.wecard.module.mayi.task;
//
//import cn.hutool.core.date.DateTime;
//import cn.hutool.core.date.DateUnit;
//import cn.hutool.core.date.DateUtil;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.krtech.wecard.module.mayi.entity.MayiDianzanCount;
//import com.krtech.wecard.module.mayi.entity.MayiDianzanLog;
//import com.krtech.wecard.module.mayi.entity.MayiMachineManage;
//import com.krtech.wecard.module.mayi.entity.MayiPayList;
//import com.krtech.wecard.module.mayi.service.MayiDianzanCountService;
//import com.krtech.wecard.module.mayi.service.MayiDianzanLogService;
//import com.krtech.wecard.module.mayi.service.MayiMachineManageService;
//import com.krtech.wecard.module.mayi.service.MayiPayListService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//
//@Component
//@Slf4j
//public class MayiDianzanCountTask {
//
//    @Autowired
//    private MayiDianzanCountService dianzanCountService;
//
//    @Autowired
//    private MayiPayListService payListService;
//
//    @Autowired
//    private MayiDianzanLogService dianzanLogService;
//
//    @Scheduled(cron = "0 0/10 * * * ?")
//    public void userTask(){
//
//        //找出未检查的
//        List<MayiDianzanCount> dianzanCountList = dianzanCountService
//                .list(new QueryWrapper<MayiDianzanCount>().eq(MayiDianzanCount.COL_HAS_CHECK,0));
//        for (MayiDianzanCount dianzanCount:dianzanCountList){
//            //判断上次存活
//            DateTime now = DateUtil.date();
//
//            if (dianzanCount.getUpdatedTime() != null){
//                long between = DateUtil.between(dianzanCount.getUpdatedTime(), now, DateUnit.MINUTE);
//                //超时十分钟
//                if (between > 10){
//                    //查询出对应的payList
//                    MayiPayList payList = payListService.getById(dianzanCount.getFkPayListId());
//
//                    //进行检查
//                    int realCount = dianzanLogService.count(new QueryWrapper<MayiDianzanLog>()
//                            .eq(MayiDianzanLog.COL_FK_PAY_LIST_ID, dianzanCount.getFkPayListId()));
//
//                    if (realCount != dianzanCount.getCount()){
//                        //说明数据错误
//                        dianzanCount.setCount(realCount);
//                        dianzanCountService.updateById(dianzanCount);
//
//                        //修正paylist数量
//                        payList.setReachCount(realCount);
//                        payListService.updateById(payList);
//                    }else {
//                        //说明数据正常，将其改为检查过
//                        dianzanCount.setHasCheck(1);
//                        dianzanCountService.updateById(dianzanCount);
//                    }
//                }
//            }
//        }
//
//
//
//
//    }
//}
